//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "MarshallOlkinCopula.h"
using namespace Cephei::QL::Math::Copulas;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Copulas::CMarshallOlkinCopula::CMarshallOlkinCopula (Double a1, Double a2) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phMarshallOlkinCopula = NULL;
#endif
        QuantLib::Real _a1 = (QuantLib::Real)ValueHelper::Convert (a1);
        QuantLib::Real _a2 = (QuantLib::Real)ValueHelper::Convert (a2);
        _ppMarshallOlkinCopula = new boost::shared_ptr<QuantLib::MarshallOlkinCopula> (new QuantLib::MarshallOlkinCopula ( _a1,  _a2 ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Copulas::CMarshallOlkinCopula::CMarshallOlkinCopula (boost::shared_ptr<QuantLib::MarshallOlkinCopula>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMarshallOlkinCopula = NULL;
#endif
	_ppMarshallOlkinCopula = &childNative;
    
}
Cephei::QL::Math::Copulas::CMarshallOlkinCopula::CMarshallOlkinCopula (QuantLib::MarshallOlkinCopula& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phMarshallOlkinCopula = NULL;
#endif
	_ppMarshallOlkinCopula = new boost::shared_ptr<QuantLib::MarshallOlkinCopula> (&childNative);
    
    _MarshallOlkinCopulaOwner = owner;
    
}

Cephei::QL::Math::Copulas::CMarshallOlkinCopula::CMarshallOlkinCopula (CMarshallOlkinCopula^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMarshallOlkinCopula = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppMarshallOlkinCopula = new boost::shared_ptr<QuantLib::MarshallOlkinCopula> (copy->GetShared());
        
    }
}
Cephei::QL::Math::Copulas::CMarshallOlkinCopula::CMarshallOlkinCopula (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMarshallOlkinCopula = NULL;
#endif
	if (!t->IsSubclassOf(CMarshallOlkinCopula::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Copulas::CMarshallOlkinCopula::CMarshallOlkinCopula (QuantLib::Handle<QuantLib::MarshallOlkinCopula>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phMarshallOlkinCopula = &childNative;
	_ppMarshallOlkinCopula = &static_cast<boost::shared_ptr<QuantLib::MarshallOlkinCopula>>(childNative.currentLink());
    
    _MarshallOlkinCopulaOwner = owner;
}
Cephei::QL::Math::Copulas::CMarshallOlkinCopula::CMarshallOlkinCopula (QuantLib::Handle<QuantLib::MarshallOlkinCopula> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phMarshallOlkinCopula = &childNative;
	_ppMarshallOlkinCopula = &static_cast<boost::shared_ptr<QuantLib::MarshallOlkinCopula>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Copulas::CMarshallOlkinCopula::CMarshallOlkinCopula (QuantLib::MarshallOlkinCopula childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMarshallOlkinCopula = NULL;
#endif
	_ppMarshallOlkinCopula = new boost::shared_ptr<QuantLib::MarshallOlkinCopula> (new QuantLib::MarshallOlkinCopula (childNative));
    
}
#endif

Cephei::QL::Math::Copulas::CMarshallOlkinCopula::~CMarshallOlkinCopula ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppMarshallOlkinCopula != NULL)
    {
	    delete _ppMarshallOlkinCopula;
        _ppMarshallOlkinCopula = NULL;
    }
}
Cephei::QL::Math::Copulas::CMarshallOlkinCopula::!CMarshallOlkinCopula ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppMarshallOlkinCopula != NULL)
    {
	    delete _ppMarshallOlkinCopula;
    }
}
QuantLib::MarshallOlkinCopula& Cephei::QL::Math::Copulas::CMarshallOlkinCopula::GetReference ()
{
    if (_ppMarshallOlkinCopula == NULL) throw gcnew NativeNullException ();
	return **_ppMarshallOlkinCopula;
}
boost::shared_ptr<QuantLib::MarshallOlkinCopula>& Cephei::QL::Math::Copulas::CMarshallOlkinCopula::GetShared ()
{
    if (_ppMarshallOlkinCopula == NULL) throw gcnew NativeNullException ();
	return *_ppMarshallOlkinCopula;
}
QuantLib::MarshallOlkinCopula* Cephei::QL::Math::Copulas::CMarshallOlkinCopula::GetPointer ()
{
    if (_ppMarshallOlkinCopula == NULL) throw gcnew NativeNullException ();
	return &**_ppMarshallOlkinCopula;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::MarshallOlkinCopula>& Cephei::QL::Math::Copulas::CMarshallOlkinCopula::GetHandle ()
{
	if (_phMarshallOlkinCopula == NULL)
	{
		_phMarshallOlkinCopula = new Handle<QuantLib::MarshallOlkinCopula> (*_ppMarshallOlkinCopula);
	}
	return *_phMarshallOlkinCopula;
}
#endif
bool Cephei::QL::Math::Copulas::CMarshallOlkinCopula::HasNative () 
{
	return (_ppMarshallOlkinCopula != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Copulas::IMarshallOlkinCopula^ Cephei::QL::Math::Copulas::CMarshallOlkinCopula_Factory::Create (Double a1, Double a2)
{
    return gcnew CMarshallOlkinCopula ( a1,  a2);
}
